package com.example.sztangli.widgedemo.RecycleListView;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.sztangli.widgedemo.R;

import java.util.List;

/**
 * Created by sztangli on 2017/8/15.
 */

public class RecyclViewAdapter extends RecyclerView.Adapter<RecyclViewAdapter.MyViewHolder> {

    protected Context context;
    protected List<RecycleBean> datas;
    public RecyclViewAdapter(Context context,List<RecycleBean> datas) {
        this.context=context;
        this.datas=datas;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder=new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_recycleview,
                parent,false));

        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
       holder.tv.setText(datas.get(position).getContent());
    }


    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
         TextView tv;
        public MyViewHolder(View itemView) {
            super(itemView);
          tv= (TextView) itemView.findViewById(R.id.tv_recycle_item);
        }
    }
}
